<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
    <style>
        #box{
            width: 300px;
            height: 200px;
            margin: 0 auto;
            border: 1px solid #999;
            border-radius: 20px;
        }
        #box form{
            margin: 40px 0 0 20px;
        }
        #box form input{
            margin: 0 0 10px 0;
        }
        #box form input[type="submit"]{
            margin-top: 10px;
            margin-left: 80px;
        }
    </style>
</head>
<body>
<div id="box">
    <form action="/register" method="post">
        用户名：<input type="text" name="username" id="username"><span id="tip"></span><br/>
        用户密码：<input type="password" name="password" id="password"><br/>
        用户角色：<select id="role" >
            <#list roles as role>
                <option value="${role.roleid}">${role.rolename}</option>
            </#list>
        </select><br/>
        <input type="button" value="注&nbsp;册" id="submit">
    </form>
</div>
</body>
<script>
    $("#submit").click(function (){
        $.ajax({
            type:"post",
            url:"/register",
            contentType: "application/json", // 设置内容类型为 JSON
            data: JSON.stringify({
                username: $("#username").val(),
                password: $("#password").val(),
                role:{
                    roleid:$("#role").val()
                }
            }),
            success: function (res){
                if (res=="true"){
                    location.href="/login"
                } else {
                    alert("注册失败")
                }
            }
        })
    })
</script>
</html>
